﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;

namespace BiliBiliDown.BLL
{
    public class Dispose
    {
       
        /// <summary>
        /// 处理成数字
        /// </summary>
        /// <param name="textav"></param>
        /// <returns></returns>
        public static int JudgeInt(string textav)
        {
            int av = 0;
            if (int.TryParse(textav, out av)) { }
            else
            {
                textav = textav.Remove(0, 2);
                if (int.TryParse(textav, out av))
                {
                    return -1;
                }
            }
            return av;
        }

        /// <summary>
        /// GET请求与获取结果
        /// </summary>
        public static string HttpGet(int av)
        {
            string url = string.Format($"http://www.bilibilijj.com/Api/AvToCid/{av}/0");
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            return retString;
        }
    }

}